//当前项目的路由模块
import Vue from 'vue'
import VueRouter from 'vue-router'

import Header from '@/components/Header.vue'
import Hcourse from '@/components/course/Hight.vue'
import SingleHCourse from '@/components/course/SingleHCourse.vue'
import Uncourse from '@/components/course/UnCourse.vue'
import Myback from '@/components/back/MyBack.vue'
import Login from '@/components/ins/Login.vue'
import Usercenter from '@/components/user/Usercenter.vue'
import Teacherregist from '@/components/userteacher/Teacherregit.vue'
import CollecCourse from '@/components/userteacher/CollecCourse.vue'
import CourseDetail from '@/components/teacher/CourseDetail.vue'

//声明Vue.use()函数，把VueRouter安装为vue插件
Vue.use(VueRouter)

//创建路由实例对象
// const router = new VueRouter({
//   //定义hash地址与组件之间的对应关系
//   routes: [
//     //路由规则
//     // {path: '/home',component:要展示的组件}
//     { path: '/home', component: Home },
//     //在movie组件中希望根据id值找到对应值,props为路由规则开启传参，接收参数更方便
//     { path: '/movie/:mid', component: Movie ,props:true},
//     {
//       path: '/about',
//       component: About,
//       // redirect: '/about/table1', //可通过默认子路由实现
//       children: [
//         //子路由规则
//         { path: '', component: Table1 }, //路径为空则是默认子路由
//         { path: 'table2', component: Table2 }
//       ]
//     },
//     //重定向路由规则
//     { path: '/', redirect: '/home' }
//   ]
// })
const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/header'},
    {path:'/header', component: Header},
    {path:'/hcourse/:username', component: Hcourse, props: true},
    //此处不采用子路由是因为刷新问题
    {path:'/hcourse/singlecourse/:coursename',component:SingleHCourse, props:true},
    {path:'/uncourse/:username',component: Uncourse, props: true},
    {path: '/myback', component: Myback},
    {path: '/login/:lorsta', component: Login, props: true},
    {path: '/usercenter/:username', component: Usercenter,props:true},
    {path: '/teacherregist/:username', component: Teacherregist,props:true},
    {path: '/collectcourse/:username', component: CollecCourse,props:true},
    {path: '/coursedetail/:coursename',component: CourseDetail,props:true}
  ]
})

//拦截
router.beforeEach(function(to,from,next){
  next()
})

//向外共享路由实例
export default router